package com.example.leetdemo.finash;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class Solution6 {

    public Solution6() {

    }

    public Solution6(int a) {
        System.err.println(1/a);
    }

    public static String convert(String s, int numRows) {
        if (numRows == 1) {
            return s;
        }
        StringBuilder[] str = new StringBuilder[numRows];
        for (int i = 0; i < numRows; i++) {
            str[i] = new StringBuilder();
        }
        int target = 1;
        for (int i = 0, k = 0; i < s.length(); i++) {
            str[k].append(s.charAt(i));
            if (k == 0) {
                target = 1;
            } else if (k == numRows - 1) {
                target = -1;
            }
            k += target;
        }
        StringBuilder z = new StringBuilder();
        for (int i = 0; i < numRows; i++) {
            z.append(str[i]);
        }
        return z.toString();
    }

    public int strStr(String haystack, String needle) {
        return haystack.indexOf(needle);
    }

    public static void main(String[] args) {
//        new Solution6(0);
        System.err.println(convert("AB", 1));
    }
}
